﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Core.Util;
using Core.IO;

namespace GPSCrowdSource.DataStructures {


  /// <summary>
  /// This provides a parser that can read a string formmatted GPS data file in the form of
  /// lat,lon,alt,time
  /// lat,lon,alt,time
  /// ...
  /// 
  /// Where lat/lon are dec degrees. Altitude is in feet, and
  /// time is Unix Epoch (milliseconds since Midnight Jan 1 1970)
  /// </summary>
  public class GPSStringDataSource : GPSListDataSource {

    #region Protected
    
    protected void Init(String s) {
      try {
        StringReader reader = new StringReader(s);
        myIdx = 0;
        myPos = new List<GeoPosition>();

        String ln;
        while((ln = reader.ReadLine()) != null) {
          myPos.Add(new GeoPosition(ln));
          }

        }
      catch(EndOfStreamException) { Close(); }
      catch(Exception ex) {Log.Error(ex); }
      }

    #endregion

    /// <summary>
    /// Inherited constructor for derived classes.
    /// </summary>
    protected GPSStringDataSource() {}

    /// <summary>
    /// This is a string data source which 
    /// </summary>
    /// <param name="s"></param>
    public GPSStringDataSource(String s) {
      Init(s);
      }


    }
  }
  